﻿Public Class businessEmpleado
    Public Function TraeTecnicosPorSucursal(ByVal Cod_Suc As Int32) As List(Of clsEmpleado)
        Dim Cn As New SqlClient.SqlConnection
        Dim Cm As New SqlClient.SqlCommand
        Dim Dr As SqlClient.SqlDataReader
        Dim ListaEmpleados As New List(Of clsEmpleado)

        Try
            Cn.ConnectionString = My.Resources.Conexion
            Cn.Open()
            Cm.CommandType = CommandType.StoredProcedure
            Cm.CommandText = "SP_TRAER_TECNICOS_X_SUCURSAL"

            Cm.Parameters.Add("@Cod_Suc", SqlDbType.Int)
            Cm.Parameters("@Cod_Suc").Value = Cod_Suc

            Cm.Connection = Cn
            Dr = Cm.ExecuteReader
            If Dr.HasRows = True Then
                While Dr.Read
                    Dim Empleado As New clsEmpleado()
                    Empleado.Emp_Id = Dr.GetInt32(0)
                    Empleado.Nombre = Dr.GetString(1).Trim.ToUpper
                    Empleado.Apellido = Dr.GetString(2).Trim.ToUpper
                    Empleado.Rol_Id = Dr.GetInt32(3)
                    Empleado.Cod_Suc = Dr.GetInt32(4)

                    Dim RolDao As New daoRoles()
                    Empleado.Rol = RolDao.TraeRol(Empleado.Rol_Id)
                    RolDao.Dispose()

                    ListaEmpleados.Add(Empleado)
                    Empleado.Dispose()

                End While
                Dr.Close()
                Cn.Close()
            End If
            Return ListaEmpleados
        Catch ex As Exception
            Throw New Exception(ex.Message)
        Finally
            Cn.Dispose()
            Cm.Dispose()
        End Try
    End Function

    Public Sub New()
        MyBase.New()
    End Sub
    Public Sub Dispose()
        MyBase.Finalize()
    End Sub
End Class
